use std::time::Duration;

/// QUIC configuration
#[derive(Debug, Clone)]
pub struct QuicConfig {
    pub init_stream_receive_window: u64,
    pub max_stream_receive_window: u64,
    pub init_connection_receive_window: u64,
    pub max_connection_receive_window: u64,
    pub max_idle_timeout: Duration,
    pub max_incoming_streams: Option<i64>,
    pub disable_path_mtu_discovery: bool,
}

impl Default for QuicConfig {
    fn default() -> Self {
        Self {
            init_stream_receive_window: 8388608,      // 8MB
            max_stream_receive_window: 8388608,       // 8MB
            init_connection_receive_window: 20971520, // 20MB
            max_connection_receive_window: 20971520,  // 20MB
            max_idle_timeout: Duration::from_secs(30),
            max_incoming_streams: Some(256),
            disable_path_mtu_discovery: false,
        }
    }
}

impl QuicConfig {
    pub fn to_quinn_config(&self) -> quinn::TransportConfig {
        let mut config = quinn::TransportConfig::default();
        
        config.initial_mtu(1200);
        config.max_idle_timeout(Some(self.max_idle_timeout.try_into().unwrap()));
        config.keep_alive_interval(Some(Duration::from_secs(10)));
        
        if let Some(max_streams) = self.max_incoming_streams {
            config.max_concurrent_bidi_streams(max_streams.try_into().unwrap());
        }
        
        config
    }
}
